﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using LinkShareWpf.Commands;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Markup;


namespace LinkShareWpf.ViewModel
{

    public  class HomeWindowViewModel
    {

        #region Events
        public event CancelEventHandler ExitCommandRequested;
        public event EventHandler ChangeUserControlCommandRequested;
        #endregion

        #region Commmands
        public DelegateCommand ExitCommand { get; private set; }
        public DelegateCommand ChangeUserControlCommand { get; private set; }
        public DelegateCommand ShowWindowCommand { get; private set; }
        #endregion

        public HomeWindowViewModel()
        {
           
           //ChangeUserControl Command
            ChangeUserControlCommand = new DelegateCommand(commandParameter => ChangeUserControl(commandParameter));

            //Exit Command
            ExitCommand = new DelegateCommand(o => Exit());

            //ShowNewWindows Command
            ShowWindowCommand = new DelegateCommand(commandParameter => ShowNewWindow(commandParameter));

            WindowHandler.Instance.ReloadUserControlRequested += ReloadUserControlEventHandler;
        }

        void ReloadUserControlEventHandler(object sender, EventArgs e)
        {
            ParameterEventArgs parArg =null;
            if((e as WindowHandler.MessageParameterEventArgs).message.Equals("LocalUserControl"))
                 parArg = new ParameterEventArgs(new LocalResourcesControl());
            else
                parArg = new ParameterEventArgs(new NetworkResourceControl());
            ChangeUserControlCommandRequested(this, parArg);
        }

        private void Exit()
        {
            ExitCommandRequested(this, new CancelEventArgs(false));
        }
        
        private void ShowNewWindow(object commandParameter )
        {
             WindowHandler.Instance.ShowWindow(commandParameter.ToString());
        }
       
        private void ChangeUserControl(object commandParameter)
        {
             ParameterEventArgs parArg = new ParameterEventArgs(commandParameter as UserControl);
             ChangeUserControlCommandRequested(this, parArg);   
        }
    }


    public class ParameterEventArgs : EventArgs
    {
        public UserControl typeOfUserControl;

        public ParameterEventArgs(UserControl nameOfUserControl)
        {
            typeOfUserControl = nameOfUserControl;
        }

    }

}
